<?php


namespace app\common\model;


use think\Model;

class OperationModel extends Model
{
    protected $name = 'operation';


    /**
     * 获取列表
     * @param string $jump_type 展示位置:mini=小程序,pc=网站
     * @return array
     */
    public static function getList(string $jump_type): array
    {
        try {
//            $time = time();
            $where = [
                'status' => 1,
//                'start_time' => ['<=',$time],
//                'end_time' => ['>=',$time],
            ];
            if(!empty($jump_type)){
                $where['jump_type'] = $jump_type;
            }
//            $field = ['id','name','image','jump_type','jump_url','jump_url_type','start_time','end_time'];
            $field = ['id','name','image','jump_type','jump_url','jump_url_type'];
            $order = [
                'weigh' => 'asc',
            ];
            $list = self::where($where)
                ->field($field)
                ->order($order)
                ->select();
            foreach ($list as $row){
                $row->image = ImageAddDomain($row->image);
                $row->jump_url = ImageAddDomain($row->jump_url);
            }
            return [
                'code' => 200,
                'msg' => '请求成功',
                'data' => $list
            ];
        }catch (\Exception $e) {
            return [
                'code' => $e->getCode(),
                'msg' => $e->getMessage(),
                'data' => []
            ];
        }
    }
}